#! /bin/sh
# PCP QA Test No. 564
# exercise archive compression thru pmlogger_daily
#
# Copyright (c) 1995-2002 Silicon Graphics, Inc.  All Rights Reserved.
#
# check-group-include: pmlogextract
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter

NEEDREWRITE=$PCP_LOG_DIR/pmlogger/.NeedRewrite

_cleanup()
{
    [ -d $tmp.distdir ] && rm -fr $tmp.distdir
    [ -d $tmp.relaydir ] && rm -fr $tmp.relaydir
    $sudo rm -f $tmp.*
    [ -f $NEEDREWRITE.$seq ] && $sudo mv $NEEDREWRITE.$seq $NEEDREWRITE
}

status=1	# failure is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

[ -f $NEEDREWRITE ] && $sudo mv $NEEDREWRITE $NEEDREWRITE.$seq

# create test control file, directories and populate with dummy archives
cat >$tmp.ctl<<EOF
\$version=1.1
#Host           P?  S?  directory       args
dist.engr       n   n   $tmp.distdir    -c config.default
relay.engr      n   n   $tmp.relaydir   -c config.default
EOF

mkdir -p $tmp.distdir $tmp.relaydir

# some archives for today...
TODAY=`pmdate %Y%m%d`
cp $tmp.ctl $tmp.distdir/$TODAY.0
cp $tmp.ctl $tmp.distdir/$TODAY.meta
cp $tmp.ctl $tmp.distdir/$TODAY.index
cp $tmp.ctl $tmp.relaydir/$TODAY.0
cp $tmp.ctl $tmp.relaydir/$TODAY.meta
cp $tmp.ctl $tmp.relaydir/$TODAY.index

# some archives for a five days ago...
FIVEDAYS=`pmdate -5d %Y%m%d`
cp $tmp.ctl $tmp.distdir/$FIVEDAYS.0
cp $tmp.ctl $tmp.distdir/$FIVEDAYS.meta
cp $tmp.ctl $tmp.distdir/$FIVEDAYS.index
cp $tmp.ctl $tmp.relaydir/$FIVEDAYS.0
cp $tmp.ctl $tmp.relaydir/$FIVEDAYS.1
cp $tmp.ctl $tmp.relaydir/$FIVEDAYS.meta
cp $tmp.ctl $tmp.relaydir/$FIVEDAYS.index
cp $tmp.ctl $tmp.relaydir/mumble
cp $tmp.ctl $tmp.relaydir/mumble.0
STAMP=`pmdate -5d %Y%m%d`0010
touch -t "$STAMP" $tmp.*/$FIVEDAYS.* $tmp.relaydir/mumble*

# some archives for five months ago...
FIVEMONTHS=`pmdate -5m %Y%m%d`
cp $tmp.ctl $tmp.distdir/$FIVEMONTHS.0
cp $tmp.ctl $tmp.distdir/$FIVEMONTHS.meta
cp $tmp.ctl $tmp.distdir/$FIVEMONTHS.index
cp $tmp.ctl $tmp.relaydir/$FIVEMONTHS.0
cp $tmp.ctl $tmp.relaydir/$FIVEMONTHS.meta
cp $tmp.ctl $tmp.relaydir/$FIVEMONTHS.index
STAMP=`pmdate -5m %Y%m%d`0010
touch -t "$STAMP" $tmp.*/$FIVEMONTHS.*

# real QA test starts here
$sudo $PCP_BINADM_DIR/pmlogger_daily -P -V -N -x 3 -X bzip2 -c $tmp.ctl 2>&1 | \
sed \
	-e '/date-and-timestamp/d' \
	-e '/^Roll .*\/NOTICES/d' \
	-e '/^Start .*\/NOTICES/d' \
	-e '/^Start \[/s/ 2[0-9:. -]*/ DATESTAMP/' \
	-e '/^End \[/s/ 2[0-9:. -]*/ DATESTAMP /' \
	-e '/^Add merge callback for: pmlogger_daily_report/d' \
	-e '/^+ mv .*\/NOTICES/d' \
	-e '/^+ touch .*\/NOTICES/d' \
	-e "s/$TODAY/TODAY/g" \
	-e "s/$FIVEDAYS/FIVEDAYS/g" \
	-e "s/$FIVEMONTHS/FIVEMONTHS/g" \
	-e "s/$seq-$$/SEQ-PID/g" \
	-e '/Warning: no archives found to merge/d' \
	-e "s;/private/;/;g" \
	-e "s,$PCP_TMP_DIR,TMP,g" \
	-e "s,/var/tmp,TMP,g" \
	-e "s,/tmp,TMP,g" \
	-e '/+ ln /d' \
# end

# success, all done
status=0
exit
